﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using VerficationsWPF.HWControls;

namespace VerficationsWPF.Models
{
    /// <summary>
    /// DialogModel.xaml 的交互逻辑
    /// </summary>
    [Info(100, true)]
    public partial class DialogModel : BaseModel
    {
        public DialogModel()
        {
            InitializeComponent();
            WindowDragger windowDragger = new WindowDragger(lblInfo);
            this.Title = "Hello";
            this.Description = "显示美化过的对话框。";
        }

        private void btnYesNoDialog_Click(object sender, RoutedEventArgs e)
        {
            var dialog = new HWControls.ButifulDialog();
            if (rbOnWindow.IsChecked == true)
            {
                dialog.ShowAt(Window.GetWindow(this));
            }
            else if (rbOnUserControl.IsChecked == true)
            {
                dialog.ShowAt(this);
            }
            else
            {
                dialog.ShowAt(btnYesNoDialog);
            }
            // dialog.ShowAt(rbOnWindow.IsChecked ? false ? btnYesNoDialog : this);

            Console.WriteLine(Window.GetWindow(this).GetType().Name);
        }

        private void btnTaskWindow_Click(object sender, RoutedEventArgs e)
        {
            TaskWindow tw = new TaskWindow();
            tw.MainTask = new Func<object>(() =>
            {
                Thread.Sleep(5_000);
                return 0;
            });
            tw.ShowAt(this);

            if (tw.Result is int v)
            {
                MessageBox.Show("经过后台如果处理，最终计算结果为：" + v, "任务完成");
            }
            else
            {
                MessageBox.Show(tw.ExitMessage, "任务未完成");
            }
        }

        private void btnConfirmWindow_Click(object sender, RoutedEventArgs e)
        {
            new ConfirmDialog().ShowAt(this);
        }
    }
}
